package org.testile.datasetmanipulation;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.dbunit.dataset.DataSetException;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.xml.XmlDataSet;
/**
 *
 * @author hvizmar
 */
public class DatasetUtils {

	private DatasetUtils() {
		throw new Error("Utility class. Should not be instantiated.");
	}

	public static IDataSet getDataSet(String path) throws IOException, DataSetException {
		IDataSet dataset = new XmlDataSet(new FileInputStream(new File(path)));
		return dataset;
	}
	
	public static IDataSet wrapIn(DatasetWrapper wrapper, String path) {
		try {
			IDataSet dataset = getDataSet(path);
			return wrapper.wrap(dataset);
		} catch (IOException ex) {
			throw new IllegalArgumentException("Could not load dataset from path [" + path + "]", ex);
		} catch (DataSetException ex) {
			throw new IllegalArgumentException("Could not load dataset from path [" + path + "]", ex);
		}
	}
}
